package LuoGu.贪心.铺设道路;

import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int ans = 0;
        int index = 0;
        for(int i=0;i<n;i++) {
            int temp = s.nextInt();
            if(temp>index) ans+=temp-index;
            index = temp;
        }
        System.out.print(ans);
    }
}

